<!DOCTYPE html>
<html lang="en">

<head>
    <title>主持费结算</title>
    <meta name=“keyword” content="主持费结算">
    <meta name="discription" content="主持费结算">
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="./css/index.css?v=0.03" media="all" />
    <link rel="shortcut icon" href="./imgs/favicon.ico">
    <meta name="format-detection" content="telephone=no" />
    <script src="./js/jquery.min.js?v=0.01"></script>
    <script src="./js/clipboardjs.js?v=0.01"></script>
</head>

<body>
    <div>
        <div class="ly-main" id="ly-main-1" style="position: absolute;z-index: 0;height:100%">
            <img class="bg-main" src="./imgs/bg-01.jpg">
        </div>

        <div class="ly-main" id="ly-main-2" style="position: relative;z-index: 1;">
            <div class="ly-main-input">
                <div class="input-panel" style="margin-top: 5%;">
                    <h1 style="    font-size: 50px;color:#bc1918">主持费结算器</h1>
                </div>
                <div class="input-panel" style="margin-top: 5%;">
                    <p class="ps">使用说明:在下方输入框中,将需要结算的主持记录全部复制进去,每行一档.然后点击开始结算<br />
                        支持的格式 :<br />
                        格-嘻-早-听-早-脸-芸-听-烦-鱼-鱼<br /><br />
                        8.20 16-17：晕-脸-晕-罐-芸-脸-la-听-鱼-鱼-win-罐-芸-听<br /><br />
                        17-18：鱼-win-win-格-笨-罐-与-77-77-笨-罐-la-与<br /><br />
                    </p>
                </div>

                <div class="input-panel" style="margin-top: 5%;" id="panel-source">
                    <textarea rows="20" id="data-source"></textarea>
                    <br />
                    <br />
                    <label class="btn-f01" onclick="start()" style="float:right">开始结算</label>
                </div>
                <div class="input-panel" style="margin-top: 5%;display: none;" id="panel-result">
                    <textarea rows="20" id="data-result" style="resize: vertical;"></textarea>
                    <p class="ps-result" style="font-size: 30px;">以上是应收主持费(请记得把自己去掉),有任何问题或者需求可以联系右下角小助手~~</p>
                    <label class="btn-f02" id="btn-cp" data-clipboard-target="#data-result"
                        style="float:right">复制结果</label>
                    <label class="btn-f02" onclick="restart()" style="float:right">重新结算</label>
                </div>

            </div>

        </div>
        <div style="clear: both;"></div>
    </div>
    <div class="cp">
        <p>图片资源 -> 微博@ROROJUMP肉肉酱 侵权立删</p>
        <br />
        <p>浙ICP备2023009543号</p>
    </div>
    <div class="contact">
        <p>有任何问题可以联系我哦</p>
        <img src="./imgs/contact.jpg?v=0.0.3">

    </div>
    <!-- <audio id="music1" controls="controls" autoplay="autoplay" preload id="music1" hidden>
        <source src="https://xuai-01.oss-cn-hangzhou.aliyuncs.com/biubiu.MP3" />
    </audio> -->
</body>
<script>

    var analisResults = []

    var STAT_RESULT = []
    $(function () {
        resizeBg();
        window.onresize = function () {
            resizeBg();
        }
        // var msg = "本站已完成迁移,请通过新的网址访问 -> https://xu-ai-better.gitee.io/zhuchifei/ 请相互告知,谢谢 ~ 管理员 2024年04月19日";
        // alert(msg)
    })

    // document.addEventListener("click", function () {
    //     var audio = document.getElementById("music1");
    //     if (audio.paused) {
    //         audio.play();
    //     }
    // });

    // $("#btn").bind("touchstart", function bf() {
    //     if (audio !== null) {
    //         //检测播放是否已暂停.audio.paused 在播放器播放时返回false.
    //         //alert(audio.paused);
    //         if (audio.paused) {
    //             audio.play(); //audio.play();// 这个就是播放
    //             $("#btn").addClass("active")
    //         } else {
    //             audio.pause(); // 这个就是暂停
    //             $("#btn").removeClass("active")
    //         }
    //     }
    // })

    var clipboard = new ClipboardJS('#btn-cp');

    clipboard.on('success', function (e) {
        console.info('Action:', e.action);
        console.info('Text:', e.text);
        console.info('Trigger:', e.trigger);
        alert("已复制到剪贴板~");

        e.clearSelection();
    });

    clipboard.on('error', function (e) {
        alert("复制失败,请手动复制");
    });

    function resizeBg() {
        var bg = $('.bg-main');
        if ($(window).width() < 1000) {
            bg.attr('src', './imgs/bg-02.jpeg');
            $(".contact").hide();
        } else {
            bg.attr('src', './imgs/bg-01.jpg');
            $(".contact").show();
        }
    }
    function start() {
        analisResults = []
        STAT_RESULT = []
        analyse();
        $("#panel-result").show();
        var textarea = document.getElementById("data-result");
        textarea.scrollTop = textarea.scrollHeight;
        $("#panel-source").hide();
    }

    function restart() {
        $("#data-result").val("");
        $("#panel-source").show();
        $("#panel-result").hide();

    }

    function analyse() {
        var source = $("#data-source").val();
        console.log('source');
        console.log(source);

        var strlist = source.split("\n");
        console.log('strlist', strlist);

        // 解析结果

        let validStrCount = 0;

        for (str of strlist) {
            if (null == str) {
                continue;
            }

            let maixu = replaceSymbol(str);
            if (null == maixu || "" == maixu) {
                continue
            }
            const analysResult = analysisLine(maixu)
            if (analysResult != null && analysResult.length > 0) {
                validStrCount++;
                analisResults.push({
                    source: str,
                    result: analysResult,
                    size: analysResult.length
                })
                for (singer of analysResult) {
                    addStat(singer)
                }
            }
        }

        STAT_RESULT.sort((a, b) => b.count - a.count);
        console.log("解析完成", STAT_RESULT)
        console.log(`有效麦序 ${validStrCount} 条`)

        let feeTotal = 0;
        let feeResultOutput = '';
        console.log(`以下是应收主持费(请记得把自己去掉)\r\n`)
        for (node of STAT_RESULT) {
            feeTotal += node.count * 3;
            feeResultOutput += `${node.singer} : ${node.count} 首  ${node.count * 3} 元\n`
        }
        feeResultOutput += `\n合计 ${feeTotal / 3} 首 ${feeTotal} 元`

        $("#data-result").val(feeResultOutput);
    }

    function analysisLine(str) {
        let maixu = str

        if (maixu.indexOf(":") > 0) {
            maixu = maixu.split(":")[1];
        }

        let singers = maixu.split("-");
        return singers;
    }

    function addStat(singer) {
        if (null == singer || '' == singer) {
            return
        }
        for (node of STAT_RESULT) {
            if (node.singer == singer) {
                node.count++;
                return;
            }
        }
        STAT_RESULT.push({
            singer: singer,
            count: 1
        })
    }

    function replaceSymbol(input) {
        let output = input.replaceAll("，", ",")
            .replaceAll("。", ".")
            .replaceAll("！", "!")
            .replaceAll("？", "?")
            .replaceAll("；", ";")
            .replaceAll("“", "\"")
            .replaceAll("”", "\"")
            .replaceAll("‘", "'")
            .replaceAll("’", "'")
            .replaceAll("《", "<")
            .replaceAll("》", ">")
            .replaceAll("（", "(")
            .replaceAll("）", ")")
            .replaceAll("【", "[")
            .replaceAll("】", "]")
            .replaceAll("：", ":")
            .replaceAll("——", "-")
            .replaceAll(" ", "");
        return output;
    }
</script>

</html>